//**************************************************
//	Digit Widgets Utility Module
// 	Just some useful Utilities, add your own! 
//	Made to be called from Hyperlinked Digit_Widgets Script
//
// Version 3.0 - 09/12/01 - Added Animation Script to Widgets
//**************************************************
<zscriptinsert,"Digit_Widgets_Common_Std.txt">

[PD]
[FontSetColor,255,200,0]3D Plane Angle Utility[FontSetColor,160,160,160]
[PD]
//*****************Plane Angle*******************************
[iSlider,"Rotate1                  ",0,5,-90,90,"Plane Angle",,0,[TextCalcWidth,SizeIncr4123]]
[IButton,"Make Plane","Create and Rotate a Ground Plane",
	//just in case someone changed the canvas size
	[VarSet,docWidth,DOCUMENT:MODIFIERS:WIDTH]
	[VarSet,docHeight,DOCUMENT:MODIFIERS:HEIGHT]
	[VarSet,docMidX,docWidth/2]
	[VarSet,docMidY,docHeight/2]
	[iPress,tool:plane3D]
	[VarSet,rot1,zscript:Rotate1]
	[canvasclick,docMidX,docMidY,docWidth,docHeight]
	[transformSet,,,,docMidX,docMidy,,rot1,0,0]
]
[PD]
[FontSetColor,255,200,0]3D Prep a 3D Cylinder Utility[FontSetColor,160,160,160]
[PD]
//****************Prep Cylinder*****************************
[VarDef,CenterZ,0]
[iSlider,"ScalX  ",0,.1,-1000,DocWidth,"Manipulate  X ", [varSet,TransXS,zscript:ScalX],0,[TextCalcWidth,SizeIncr4123]]
[iSlider,"ScalY  ",0,.1,-1000,DocHeight,"Manipulate Y",[varSet,TransYS,zscript:ScalY],0,[TextCalcWidth,SizeIncr4123]]
[iSlider,"ScalZ  ",0,.1,-2000,2000,"Manipulate  Z",[varSet,TransZS,zscript:ScalZ],0,[TextCalcWidth,SizeIncr4123]]
[iSlider,"Center  ",0,.1,-100,100,"Center Point",[varSet,CenterZ,zscript:Center],0,[TextCalcWidth,SizeIncr4123]]
[IButton,Prep Cylinder,"Set XY to  and lengthen X and adjust imbed.",
	[IPress,TOOL:Cylinder3D]
	[ISet,TOOL:MODIFIERS:INITIALIZE:X Size,100]
	[ISet,TOOL:MODIFIERS:INITIALIZE:X Size,25]
	[ISet,TOOL:MODIFIERS:INITIALIZE:Y Size,100]
	[ISet,TOOL:MODIFIERS:INITIALIZE:Y Size,25]
	[IModSet,TOOL:MODIFIERS:DEFORMATION:Offset,0]
	[IModSet,TOOL:MODIFIERS:DEFORMATION:Offset,4]
	[ISet,TOOL:MODIFIERS:DEFORMATION:Offset,0]
	[ISet,TOOL:MODIFIERS:DEFORMATION:Offset,CenterZ]
	[CanvasStroke,(ZObjStrokeV01n53x2=H253V263H253V263H253V264H253V265H253V266H254V267H254V268H254V269H254V270H255V271H255V272H255V273H256V273H256V274H256V277H257V278H257V279H257V282H257V283H257V284H257V285H257V286H257V287H257V288H257V289H257V290H257V291H257V292H257V295H257V296H258V297H258V298H258V301H258V302H258V305H258V306H258V309H258V310H258V313H258V314H258V315H258V318H258V319H259V319H259V320H259V321H259V322H259V323H260V324H260V325H261V325H262V326H262V326)]
	[IPress,TRANSFORM:MOVE]
	[transformSet,,,,TransXS,TransYS,TransZS]
]
[PD]
[FontSetColor,255,200,0]Make a Rope [FontSetColor,160,160,160]
[PD]
[IButton,"Rope","Prepare a Cube3D Rope",
	[IPress,TOOL:Cube3D]
	[ISet,TOOL:Modifiers:Initialize:XSize,6]
	[ISet,TOOL:Modifiers:Initialize:YSize,6]
	[ISet,TOOL:Modifiers:Initialize:SidesCount,6]
	[ISet,TOOL:Modifiers:Initialize:HDivide,30]
	[ISet,TOOL:Modifiers:Initialize:VDivide,45]
	[ISet,TOOL:Modifiers:Initialize:Twist,100]
	[ISet,TOOL:Modifiers:Initialize:Twist,100]
	[ISet,TOOL:Modifiers:Initialize:Twist,100]
	[ISet,TOOL:Modifiers:Initialize:Twist,100]
	[ISet,TOOL:Modifiers:Initialize:Twist,100]
	[ISet,TOOL:Modifiers:Initialize:Twist,100]
	[MessageOK,"Done apply to canvas and continue to edit"]
]
[PD]
[FontSetColor,255,200,0]Center and Size a 3D Line between Marks [FontSetColor,160,160,160]
[PD]
[iSlider,"StartMark  ",1,1,1,10,"Starting Mark",[varSet,sel1,zscript:StartMark],0,[TextCalcWidth,XYAngle12345]]
[iSlider,"EndMark    ",2,1,1,10,"Ending Mark",[varSet,sel2,zscript:EndMark],0,[TextCalcWidth,XYAngle12345]]
[iSlider,"Distance   ",2,.1,0,4000,"3D Distance between Marks",,0,[TextCalcWidth,XYAngle12345]]
[IButton,"3D Line","Make a 3D Line using the current object",
	//find center
	[VarSet,sel1,[Iget,zscript:StartMark]]
	[VarSet,sel2,[Iget,zscript:EndMark]]
	//Do the line
	[RoutineCall,MakeLine,MarkX(sel1),MarkX(sel2),MarkY(sel1),MarkY(sel2),MarkZ(sel1),MarkZ(sel2),MarkZR(sel2)]
	//make scaling right
	[TransformSet,,,,MarkXS(sel2),MarkYS(sel2)]
	//distance is returned with DDistToMark
	[ISet,zscript:Distance,DDistToMark*.5]
]
[PD]
[FontSetColor,255,200,0]Press Grabline and Click and Drag to make a 3D Line between two points [FontSetColor,160,160,160]
[PD]
[iSlider,"LineDiameter  ",10,1,1,500,"Line Diameter",[varSet,Ldiam,zscript:LineDiameter],0,[TextCalcWidth,XYAngle12345]]

[iButton," MakeALine ","Press to Start then use Mouse and drag from start to end",
	[RoutineCall,Mouselook,Hval1,Vval1,Hval2,Vval2,Clicked]
	//we know we always want to look at first position
	[if,Clicked = 1,
		[RoutineCall,PixolLook,Hval1,Vval1,1,Zval1,tmp,tmp,tmp]
		[RoutineCall,PixolLook,Hval2,Vval2,1,Zval2,tmp,tmp,tmp]
		//figure out the line here now that we have the Z values and positions	
		//place current selection on canvas and go to edit
		[canvasClick,320,258,320,264]
		[iPress,transform:Move]

		//Do the line
		[RoutineCall,MakeLine,Hval1,Hval2,Vval1,Vval2,Zval1,Zval2,0]
		//make scaling right
		[TransformSet,,,,Ldiam,Ldiam]
	]
] // end iButton
[PD]
[VarDef,Point1x,0]
[VarDef,Point1y,0]
[IButton,"RandomGear","Make a Random Gear",
	[ISet,Tool:ItemInfo,39]
	

	// Set the gear to maximum resolution
	[ISet,TOOL:MODIFIERS:INITIALIZE:SDivide,128]
	[ISet,TOOL:MODIFIERS:INITIALIZE:LDivide,512]


	// Set the gear in the center and 1000 units back
	[transformSet,DocMidX,DocMidY,1000,100,100,100,0,0,0]

	// Set some random points in the cross-section
	[loop,5,
		[VarSet,point1x,rand(117)]
		[VarSet,point1y,rand(117)]
		[IClick,TOOL:MODIFIERS:INITIALIZE:Outer Section,point1x,point1y,-200,-200,point1x,point1y]
	]

	// Move the point at the right all the way to the bottom of the ZGraph
	// For some reason, this was the only point I could change via the ZScript
	[IClick,TOOL:MODIFIERS:INITIALIZE:Outer Profile,117,61,117,117]

	// Set some random points in the Outer Profile	
	[loop,7,
		[VarSet,point1x,rand(117)]
		[VarSet,point1y,rand(117)]
		[IClick,TOOL:MODIFIERS:INITIALIZE:Outer Profile,point1x,point1y,-200,-200,point1x,point1y]
	]

	// Set some random points in the Inner Section
	[IClick,TOOL:MODIFIERS:INITIALIZE:Inner Section,23,10,-100,-100,rand(29),rand(115)]
	[IClick,TOOL:MODIFIERS:INITIALIZE:Inner Section,46,10,-100,-100,23+rand(29),rand(115)]
	[IClick,TOOL:MODIFIERS:INITIALIZE:Inner Section,69,10,-100,-100,46+rand(29),rand(115)]
	[IClick,TOOL:MODIFIERS:INITIALIZE:Inner Section,92,10,-100,-100,69+rand(29),rand(115)]
	[IClick,TOOL:MODIFIERS:INITIALIZE:Inner Section,115.10,-100,-100,92+rand(29),rand(115)]

	// Set Width, Skew, Outer Radial Count, Inner Radial Count, Outer Size, Inner Radius and Tilt to Random Values
	[ISet,TOOL:MODIFIERS:INITIALIZE:Width,5+rand(70)]
	[ISet,TOOL:MODIFIERS:INITIALIZE:Skew,-100+rand(200)]
	[ISet,TOOL:MODIFIERS:INITIALIZE:OuterRC,6+rand(10)]
	[ISet,TOOL:MODIFIERS:INITIALIZE:InnerRC,3+rand(7)]
	[ISet,TOOL:MODIFIERS:INITIALIZE:OuterS,20+rand(80)]
	[ISet,TOOL:MODIFIERS:INITIALIZE:IRadius,10+rand(90)]
	[ISet,TOOL:MODIFIERS:INITIALIZE:Tilt,340+rand(20)]

	// This is so the gear can be scaled uniformly in all directions
	[varSet,Scale,50+rand(140)]
	[Note,"Completed - Drag onto Canvas to create",,3]
]
[PD]
[IButton,"RandomHelix","Make a Random Gear",
	[ISet,Tool:ItemInfo,20]

	// Set the gear to maximum resolution
	[ISet,TOOL:MODIFIERS:INITIALIZE:SDivide,128]
	[ISet,TOOL:MODIFIERS:INITIALIZE:LDivide,512]


	// Set the gear in the center and 1000 units back
	[transformSet,DocMidX,DocMidY,1000,100,100,100,0,0,0]

	// Set Width, Skew, Outer Radial Count, Inner Radial Count, Outer Size, Inner Radius and Tilt to Random Values
	[ISet,TOOL:MODIFIERS:INITIALIZE:Coverage,1+rand(359)]

	// Move the point at the right all the way to the bottom of the ZGraph
	// For some reason, this was the only point I could change via the ZScript
	[IClick,TOOL:MODIFIERS:INITIALIZE:Profile,117,61,117,117]

	// Set some random points in the cross-section
	[loop,7,
		[VarSet,point1x,rand(117)]
		[VarSet,point1y,rand(117)]
		[IClick,TOOL:MODIFIERS:INITIALIZE:Profile,point1x,point1y,-200,-200,point1x,point1y]
	]

	// Set some random points in the Outer Profile
	[loop,3,
		[VarSet,point1x,rand(117)]
		[VarSet,point1y,rand(117)]
		[IClick,TOOL:MODIFIERS:INITIALIZE:Thickness,point1x,point1y,-200,-200,point1x,point1y]
	]

	// Set some random points in the Outer Profile graph
	[loop,4,
		[VarSet,point1x,rand(117)]
		[VarSet,point1y,rand(117)]
		[IClick,TOOL:MODIFIERS:INITIALIZE:Radius,point1x,point1y,-200,-200,point1x,point1y]
	]
	// Set some random points in the Inner Section
	[IClick,TOOL:MODIFIERS:INITIALIZE:ZOffset,23,10,-100,-100,rand(29),rand(115)]
	[IClick,TOOL:MODIFIERS:INITIALIZE:ZOffset,46,10,-100,-100,23+rand(29),rand(115)]
	[IClick,TOOL:MODIFIERS:INITIALIZE:ZOffset,69,10,-100,-100,46+rand(29),rand(115)]
	[IClick,TOOL:MODIFIERS:INITIALIZE:ZOffset,92,10,-100,-100,69+rand(29),rand(115)]
	[IClick,TOOL:MODIFIERS:INITIALIZE:ZOffset,115.10,-100,-100,92+rand(29),rand(115)]

	[IClick,TOOL:MODIFIERS:INITIALIZE:Twist,115.10,-100,-100,92+rand(29),rand(115)]

	// This is so the gear can be scaled uniformly in all directions
	[varSet,Scale,50+rand(140)]
	[Note,"Completed - Drag onto Canvas to create",,3]
]
[PD]
[pd][penMove,0,8]
<zscriptinsert,"Widgets_Index_Include_Std.txt">
[pd][penMove,0,8]
\C00e0e0About This ZScript:\Cc0c0c0
This script contains a number of useful utilities some of which are self explanatory. You can add your own often used Zscripts by pasting them into this file for added functionality.
\Cffa000Plane Angle\Cc0c0c0 will create a Plane3D the size of the current canvas and at the Rotation Angle that you set in the \Cffa000Rotate1\Cc0c0c0 slider.
\C00e0e0MakeALine\Cc0c0c0 Use this function to place and lengthen a object between two points. To do this simply choose an object in your tool box, \Cffa000Cylinder3D\Cc0c0c0 makes a good round line and press the \Cffa000MakeALine\Cc0c0c0 button. The script is now looking at the mouse. Take the mouse and click and hold the left mouse button on the start of the line, then drag until you reach where you want the end to be and let go of the button. The script will then place the selected object and lengthen it to fit in between the two points. This is a little different than the other routines in that you don't have to have the object in a MOVE, SCALE or ROTATION mode. Also since the mouse looks at the surface you may need to adjust the Zdepth a bit to fit.
\Cffa000Center and Size a Line Between Two Points\Cc0c0c0 is almost the same as \Cffa000MakeALine\Cc0c0c0 except it will do the line between two selected Postion Markers that you have defined.
\Cffa000Make a Rope\Cc0c0c0 Press this and make a Rope! After the function is done, drag the mouse on the canvas to create the rope to size. Tip: Make a Rope and use it for you \Cffa000MakeALine\Cc0c0c0 function.
[PD]
[iButton,"Example ","Utility Widget Example",
	[if,[Ireset],
	[IcolorSet,239,234,30]
	[Note,"Most of these are pretty straightforward but I will show you a couple - NOTE Only run one at a time otherwise it will get ugly :)",zscript:example,3]
	[if,[MessageYesNo,"Want to know how to make a ground plane?"],
		[Note,"Make a Ground Plane - we set Rotate1 to 65 and press MakePlane",zscript:example,0]
		[ISet,zscript:Rotate1,65]
		[Note,"Setting Angle to 65",zscript:example,2]
		[Note,"Pressing MakePlane",zscript:example,2]
		[IPress,zscript:MakePlane]
		[Note,"Now you can press W and move the plane down to the bottom of the screen and you have Ground!",zscript:example,0]
	]
	[if,[MessageYesNo,"Want to know how to make a Rope?"],
		[Note,"Make a Rope - Select any tool a cube is good and press this button",zscript:example,0]
		[note,"Changing the Tool to a cube",zscript:example,1]
		[ISet,Tool:ItemInfo,9]
		[note,"Pressing Rope",zscript:example,3]
		[IPress,zscript:rope]
	]
	[if,[MessageYesNo,"Want to know how to make a Line between two Position Markers?"],
		[note,"This utility will automatically size and rotate an object to fit between two Position Markers",zscript:example,4]
		[note,"A Cylinder3D makes a perfect line",zscript:example,0]
		[ISet,Tool:ItemInfo,8]
		[CanvasClick,DocMidX,DocMidY,DocMidX+10,DocMidY+10]
		[IPress,Transform:Move]
		[TransformSet,100,100,0,20,20,20,0,45,-180]
		[IPress,Transform:Snapshot]
		[note,"Saving this one as Position Marker 1",zscript:example,3]
		[ISet,zscript:SelectMark,1]
		[IPress,zscript:Save]
		[TransformSet,400,400,-200,20,20,20,0,45,-180]
		[IPress,Transform:Snapshot]
		[note,"Moving.....",zscript:example,4]
		[note,"Saving this one as Position Marker 2",zscript:example,3]
		[ISet,zscript:SelectMark,2]
		[IPress,zscript:Save]
		[Note,"Now we will select the Cylinder3D and set the LineDiameter to 20",zscript:example,0]
		[ISet,Tool:ItemInfo,10]
		[ISet,zscript:LineDiameter,20]
		[CanvasClick,DocMidX,DocMidY,DocMidX+10,DocMidY+10]
		[IPress,Transform:Move]
		[note,"We drag our cylinder onto the canvas and press w for move",zscript:example,0]
		[Note,"Pressing 3D Line",zscript:example,3]
		[IPress,zscript:3DLine]
		[note,"Ta Da! The other function MakeALine does the same thing except after you press MakeALine use the mouse to drag from Start to End without the need for Position Marks",zscript:example,0]
	]
,//else
	[Note,"Aborting! Maybe another day eh?",,3]
]
]
[PD]
[PD]
[fontSetSizeSmall]\C00e0e0Standard Digit Widget Utility Revision 1.0, created by Digits\Cc0c0c0
